<template>
  <view class="container">
    <!-- 房源图片轮播区 -->
    <view class="house-images">
      <swiper class="swiper" circular>
        <swiper-item>
          <view class="video-container" @click="goToVideo">
            <image :src="detail.post_url" ></image>
            <view class="play-button">
              <image src="/static/building/play.png"  class="play-icon"></image>
            </view>
          </view>
        </swiper-item>
        <swiper-item v-for="item in detail.imageList" :key="item">
          <image :src="item"  @click="viewImage(item)"></image>
        </swiper-item>
      </swiper>
      <!--        <view class="image-count">-->
      <!--          <uni-icons type="image" size="14" color="#fff"></uni-icons>-->
      <!--          <text>1/6</text>-->
      <!--        </view>-->
    </view>
    <!-- 价格信息区 -->
    <view class="price-info">
      <view class="price-item">
        <text class="price">{{ detail.area || 0 }}㎡</text>
        <text class="label">面积</text>
      </view>
      <view class="price-item">
        <text class="price">{{ detail.unit_price }}元/㎡/天</text>
        <text class="label">租金单价</text>
      </view>
      <view class="price-item">
        <text class="price">{{ detail.total_price }}元</text>
        <text class="label">月租金</text>
      </view>
    </view>
    <!-- 房源标题 -->
    <view class="house-title">
      <text class="title">{{ detail.building_name }}</text>
    </view>
    <!-- 房源详情 -->
    <view class="house-detail">
      <view class="detail-item">
        <view class="label">位置</view>
        <text class="value">{{ detail.address || '-' }}</text>
      </view>
      <view class="detail-item">
        <view class="label">类型</view>
        <text class="value">{{ detail.building_type || '-' }}</text>
      </view>
      <view class="detail-item">
        <view class="label">所在楼层</view>
        <text class="value">{{ detail.floor_str || '-' }}层/共{{ detail.total_floors || '-'}}层</text>
      </view>
      <view class="detail-item">
        <view class="label">注册</view>
        <text class="value">{{ detail.can_register ? '可注册' : '不可注册' }}</text>
      </view>
      <view class="detail-item">
        <view class="label">可分割</view>
        <text class="value">{{ detail.can_divide ? '可分割' : '不可分割' }}</text>
      </view>

      <view class="detail-item">
        <view class="label">装修</view>
        <text class="value">{{ detail.decoration }}</text>
      </view>
      <view class="detail-item">
        <view class="label">得房率</view>
        <text class="value">{{ detail.efficiency }}%</text>
      </view>
      <view class="detail-item">
        <view class="label">租期</view>
        <text class="value">起租{{ detail.lease_count }} 月</text>
      </view>
      <view class="detail-item">
        <view class="label">支付</view>
        <text class="value">预付{{ detail.payment_count }}个月，押金{{ detail.deposit_count }}个月</text>
      </view>
      <view class="detail-item">
        <view class="label">物业费</view>
        <template >
          <text class="value">{{ detail.property_fee || 0}}元/㎡/天</text>
        </template>
      </view>
      <view class="detail-item">
        <view class="label">停车费</view>
        <text class="value">{{ detail.parking_fee }}元/月/辆</text>
      </view>

      <view class="house-tags">
        <text class="tag" v-for="item in detail.tagList">{{ item }}</text>
      </view>
    </view>
    <!-- 经纪人信息 -->
    <view class="agent-info">
      <image class="avatar" src="https://ai-public.mastergo.com/ai/img_res/e67289c1d3fc83e16fef76619965cb6f.jpg" mode="aspectFill"></image>
      <view class="agent-detail">
        <text class="name">陈方圆</text>
        <text class="title" style="margin-left: 12px">房产经纪人</text>
      </view>
      <view class="contact-buttons">
        <view class="contact-btn message" style="width: 45px">
          <image style="width: 24px;height: 24px" src="/static/building/msg.png" />
        </view>
        <view class="contact-btn phone"  style="width: 45px">
          <image style="width: 24px;height: 24px" src="/static/building/tel.png" />
        </view>
      </view>
    </view>
    <!-- 房源描述 -->
    <view class="house-desc">
      <view class="section-title">房源详情</view>
      <text class="desc-text">{{ detail.building_description }}</text>
      <view class="section-title section-sub-title" v-if="detail.subway_info">地铁信息：</view>
      <text class="desc-text" v-for="item in (detail.subway_info || '').split(';')"> {{ item }}</text>
      <view class="section-title section-sub-title" v-if="detail.bus_info">公交信息：</view>
      <text class="desc-text" v-for="item in (detail.bus_info || '').split(';')"> {{ item }}</text>
      <view class="section-title section-sub-title" v-if="detail.commercial_facilities">商超配套：</view>
      <text class="desc-text" v-for="item in (detail.commercial_facilities || '').split(';')"> {{ item }}</text>
      <view class="section-title section-sub-title" v-if="detail.hotel_facilities">酒店配套：</view>
      <text class="desc-text" v-for="item in (detail.hotel_facilities || '').split(';')"> {{ item }}</text>
      <view class="section-title section-sub-title" v-if="detail.administrative_facilities">行政配套：</view>
      <text class="desc-text" v-for="item in (detail.administrative_facilities || '').split(';')"> {{ item }}</text>
      <view class="section-title section-sub-title" v-if="detail.project_facilities">项目配套：</view>
      <text class="desc-text" v-for="item in (detail.project_facilities || '').split(';')"> {{ item }}</text>
    </view>
    <FacilitiesList :facilities="detail.facilitiesList"></FacilitiesList>
    <!-- 底部按钮 -->
    <view class="bottom-bar">
      <view class="price-total">
        <text class="total">{{ totalPrice }}万</text>
        <text class="unit">含{{ detail.payment_count }}个月租金及{{ detail.deposit_count }}个月押金</text>
      </view>
      <view class="action-buttons">
        <button class="contact-btn2">收藏房源</button>
      </view>
    </view>
  </view>
</template>

<script>
import FacilitiesList from "./facilitiesList.vue";
import { roundToDecimalPlace } from "../../utils/index.js"
export default {
  components: { FacilitiesList },
  data() {
    return {
      scrollHeight: 0,
      detail: {
        imageList: [],
        tagList: [],
        facilitiesList: []
      },
      itemList: []
    }
  },
  computed: {
    totalPrice() {
      // payment_count 租金个数 deposit_count 押金个数
      return roundToDecimalPlace(this.detail.total_price * (this.detail.payment_count + this.detail.deposit_count) / 1000)
    }
  },
  onLoad(options) {
    // 获取系统信息设置滚动区域高度
    const systemInfo = uni.getSystemInfoSync()
    this.scrollHeight = systemInfo.windowHeight

    // 获取房源详情
    this.getDetail(options.id)
  },
  methods: {
    viewImage(image) {
      uni.previewImage({
        current: image,
        urls: this.detail.imageList
      })
    },
    getDetail(id) {
      this.$api.getOfficeBuildingDetail(id).then(res => {
        let imageList = (res.image_url || []).map(item => item.url)
        let tagList = []
        if (res.tags) {
          tagList = res.tags.split(',').filter(item => item)
        }
        let facilitiesList = []
        if (res.facilities) {
          facilitiesList = res.facilities.split(',').filter(item => item)
        }
        let subwayInfoList = []
        if (res.subway_info) {
          subwayInfoList = res.subway_info.split(';')
        }
        this.detail = {
          ...res,
          imageList: imageList,
          tagList: tagList,
          facilitiesList: facilitiesList,
          total_price: res.price,
          unit_price: res.day_price,
          subwayInfoList
        }
      })
    },
    goToVideo() {
      if (this.detail.video_url) {
        uni.navigateTo({
          url: `/pages/house/video?url=${encodeURIComponent(this.detail.video_url)}`
        })
      }
    },
  }
}
</script>

<style>
page {
  height: 100%;
  overflow: auto;
  background-color: #f8f8f8;
}
.container {
  width: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: 100rpx;
}
.house-images {
  position: relative;
  width: 750rpx;
  height: 400rpx;
}
.house-images .swiper {
  width: 100%;
  height: 100%;
}
.house-images image {
  width: 100%;
  height: 100%;
}
.image-count {
  position: absolute;
  right: 20rpx;
  bottom: 20rpx;
  background: rgba(0, 0, 0, 0.6);
  padding: 4rpx 16rpx;
  border-radius: 20rpx;
  display: flex;
  align-items: center;
}
.image-count text {
  color: #fff;
  font-size: 24rpx;
  margin-left: 8rpx;
}
.price-info {
  display: flex;
  padding: 30rpx;
  background: #fff;
  margin-bottom: 20rpx;
}
.price-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.price-item .price {
  color: #ff5a5f;
  font-size: 32rpx;
  font-weight: bold;
  margin-bottom: 8rpx;
}
.price-item .label {
  color: #999;
  font-size: 24rpx;
}
.house-title {
  background: #fff;
  padding: 30rpx;
  margin-bottom: 20rpx;
}
.house-title .title {
  font-size: 32rpx;
  color: #333;
  font-weight: bold;
  line-height: 1.4;
}
.house-tags {
  margin-top: 16rpx;
  display: flex;
  flex-wrap: wrap;
  gap: 12rpx;
}
.house-tags .tag {
  padding: 4rpx 16rpx;
  background: #f0f7ff;
  color: #2b85e4;
  border-radius: 4rpx;
  font-size: 24rpx;
}
.house-detail {
  background: #fff;
  padding: 30rpx;
  margin-bottom: 20rpx;
  display: flex;
  flex-wrap: wrap;
}
.detail-item {
  width: 100%;
  margin-bottom: 20rpx;
  display: flex;

}
.detail-item .label {
  color: #999;
  font-size: 26rpx;
  margin-right: 20rpx;
  width: 100rpx;
}
.detail-item .value {
  color: #333;
  font-size: 26rpx;
}
.agent-info {
  background: #fff;
  padding: 30rpx;
  margin-bottom: 20rpx;
  display: flex;
  align-items: center;
}
.agent-info .avatar {
  width: 80rpx;
  height: 80rpx;
  border-radius: 50%;
}
.agent-info .agent-detail {
  flex: 1;
  margin-left: 20rpx;
}
.agent-info .name {
  font-size: 28rpx;
  color: #333;
  font-weight: bold;
}
.agent-info .title {
  font-size: 24rpx;
  color: #666;
}
.contact-buttons {
  display: flex;
  gap: 20rpx;
}
.contact-btn {
  height: 72rpx;
  border-radius: 36rpx;
  background-color: #f0f7ff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.house-desc {
  background: #fff;
  padding: 30rpx;
  margin-bottom: 20rpx;
}
.section-title {
  font-size: 36rpx;
  color: #333;
  font-weight: bold;
  margin-bottom: 20rpx;
}
.section-sub-title {
  font-size: 28rpx;
  margin-bottom: 6rpx;
  margin-top: 24rpx;
}
.desc-text {
  font-size: 26rpx;
  color: #666;
  line-height: 1.6;
}
.location-info {
  background: #fff;
  padding: 30rpx;
  margin-bottom: 20rpx;
}
.location-info .address {
  display: flex;
  align-items: center;
  gap: 10rpx;
  margin-bottom: 20rpx;
  font-size: 26rpx;
  color: #666;
}
.map-image {
  width: 100%;
  height: 200rpx;
  border-radius: 12rpx;
  margin-bottom: 20rpx;
}
.distance-info {
  display: flex;
  flex-direction: column;
}
.distance-info text {
  font-size: 24rpx;
  color: #666;
  margin-bottom: 10rpx;
}
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  padding: 20rpx 30rpx;
  display: flex;
  align-items: center;
  box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
}
.price-total {
  flex: 1;
}
.price-total .total {
  font-size: 36rpx;
  color: #ff5a5f;
  font-weight: bold;
}
.price-total .unit {
  font-size: 24rpx;
  color: #999;
  margin-left: 10rpx;
}
.action-buttons {
  display: flex;
  gap: 20rpx;
}
.contact-btn2 {
  background: #f5f5f5;
  color: #333;
  font-size: 28rpx;
  padding: 0 40rpx;
  height: 80rpx;
  line-height: 80rpx;
  border-radius: 40rpx;
}
.phone-btn {
  background: #07c160;
  color: #fff;
  font-size: 28rpx;
  padding: 0 40rpx;
  height: 80rpx;
  line-height: 80rpx;
  border-radius: 40rpx;
}
.video-container {
  position: relative;
  width: 100%;
  height: 100%;
}
.play-button {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 80rpx;
  height: 80rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}
.play-icon {
  width: 40rpx;
  height: 40rpx;
}
</style>
